﻿@model Entity.Admin.Message
@{
    Layout = null;
    ViewBag.Title = "Create";
}
<style>
    .ui-autocomplete-loading
    {
        background: white url('@Url.Content("~/Content/images/ui-anim_basic_16x16.gif")') right center no-repeat;
    }
</style>
<script type="text/javascript">
    $(function () {
        function split(val) {
            return val.split(/,\s*/);
        }
        function extractLast(term) {
            return split(term).pop();
        }

        $("#Receivers")
        // don't navigate away from the field on tab when selecting an item
			.bind("keydown", function (event) {
			    if (event.keyCode === $.ui.keyCode.TAB &&
						$(this).data("autocomplete").menu.active) {
			        event.preventDefault();
			    }
			})
			.autocomplete({
			    source: function (request, response) {
			        $.getJSON("@Url.Action("GetUser", "User")", {
			            term: extractLast(request.term)
			        }, response);
			    },
			    search: function () {
			        // custom minLength
			        var term = extractLast(this.value);
			        if (term.length < 1) {
			            return false;
			        }
			    },
			    focus: function () {
			        // prevent value inserted on focus
			        return false;
			    },
			    select: function (event, ui) {
			        var terms = split(this.value);
			        // remove the current input
			        terms.pop();
			        // add the selected item
			        terms.push(ui.item.value);
			        // add placeholder to get the comma-and-space at the end
			        terms.push("");
			        this.value = terms.join(", ");
			        return false;
			    }
			});
    });
</script>

<div class="viewActionBtns">
    @Ajax.ActionLink(SharedResource.Back, "UserSendMessages", new { pageIndex = Request.QueryString["pageIndex"], menuId = Request.QueryString["menuId"] }, new CustomAjaxOptions() { UpdateTargetId = "tabs-2" }, new { @class = "ui-state-default" })
</div>
@using (Ajax.BeginForm(new CustomAjaxOptions()))
{
    @Html.ValidationSummary(true)
    <table class="default">
        <tbody>
            <tr>
                <th>
                    接收者
                </th>
                <td>@Html.TextBox("Receivers", null, new { style="width:500px;"})
                </td>
            </tr>
            <tr>
                <th>
                    内容
                </th>
                <td>@Html.TextArea("Contents", new { style = "width:500px;" })
                </td>
            </tr>
            <tr>
            <th>&nbsp;</th>
                <td>
                    <input type="submit" value="发送" class="ui-state-default" />
                </td>
            </tr>
        </tbody>
    </table>
}